package com.banshuibao.bsb_android.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.banshuibao.bsb_android.Constants;
import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.adapter.CoachPolicyAdapter;
import com.banshuibao.bsb_android.http.HttpResponse;
import com.banshuibao.bsb_android.http.HttpUtil;
import com.banshuibao.bsb_android.model.CoachInterpretationModel;
import com.banshuibao.bsb_android.util.GetLoginInfo;
import com.banshuibao.bsb_android.util.IntentManager;
import com.banshuibao.bsb_android.util.ShareUtil;


/**
 * Created by zyh on 2017/7/10.
 */

public class CoachPolicyDetailActivity extends BaseActivity {

    private TextView go_interpretation, share;

    private RecyclerView recyclerView;

    private CoachPolicyAdapter adapter;

    private String uuid, _title;

    private long _time;
    private GetLoginInfo getLoginInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coach_policy_detail);
        getLoginInfo = GetLoginInfo.getLoginInfoInstance(this).readUser();
        initData();
        initView();
        loadData();
    }

    private void initData() {
        uuid = getIntent().getStringExtra("uuid");
        _title = getIntent().getStringExtra("title");
        _time = getIntent().getLongExtra("time", 0);
    }


    private void initView() {
        setTitleText("最新财税政策同步辅导详情");
        share = findViewById(R.id.menu);
        share.setVisibility(View.VISIBLE);
        share.setText("分享");
        recyclerView = findViewById(R.id.listView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new CoachPolicyAdapter(this);
        adapter.setTitle(_title);
        adapter.setTime(_time);
        recyclerView.setAdapter(adapter);
        go_interpretation = findViewById(R.id.go_interpretation);
        go_interpretation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IntentManager.goCoachInterpretationActivity(CoachPolicyDetailActivity.this, uuid);
            }
        });

        share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ShareUtil.showShare(CoachPolicyDetailActivity.this, Constants.Url.COACH + uuid+"&firmId="+getLoginInfo.getFirmId()+"&inviteUserId="+getLoginInfo.getUserId(),  _title,"", null);
            }
        });
    }

    private void loadData() {
        CoachInterpretationModel.Body body = new CoachInterpretationModel.Body();
        body.setUuid(uuid);
        body.setType(CoachInterpretationModel.Body.POLICY_TYPE);
        HttpUtil.doPost(Constants.Url.POLICY_DETAILS, body, new HttpResponse(this, CoachInterpretationModel.class) {
            @Override
            public void onResult(Object obj) {
                CoachInterpretationModel model = (CoachInterpretationModel) obj;
                if (adapter != null)
                    adapter.setData(model.getData());
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}
